{% extends 'base.html' %}

{% block title %}编辑碳排放系数{% endblock %}

{% block content %}
<div class="container mt-4">
    <div class="card">
        <div class="card-header">
            <h4>编辑碳排放系数</h4>
        </div>
        <div class="card-body">
            {% with messages = get_flashed_messages(with_categories=true) %}
                {% if messages %}
                    {% for category, message in messages %}
                        <div class="alert alert-{{ category }}">{{ message }}</div>
                    {% endfor %}
                {% endif %}
            {% endwith %}

            <form method="POST">
                <input type="hidden" name="id" value="{{ coefficient.id }}">
                
                <div class="mb-3">
                    <label for="name" class="form-label">系数名称</label>
                    <input type="text" class="form-control" id="name" name="name" value="{{ coefficient.name }}" required>
                </div>
                
                <div class="mb-3">
                    <label for="value" class="form-label">系数值</label>
                    <input type="number" step="0.000001" class="form-control" id="value" name="value" value="{{ coefficient.value }}" required>
                </div>
                
                <!-- 添加单位字段 -->
                <div class="mb-3">
                    <label for="unit" class="form-label">单位</label>
                    <input type="text" class="form-control" id="unit" name="unit" value="{{ coefficient.unit }}" required>
                </div>
                
                <div class="mb-3">
                    <label for="gas" class="form-label">气体类型</label>
                    <select class="form-select" id="gas" name="gas" required>
                        <option value="CO2" {% if coefficient.gas == 'CO2' %}selected{% endif %}>二氧化碳 (CO2)</option>
                        <option value="CH4" {% if coefficient.gas == 'CH4' %}selected{% endif %}>甲烷 (CH4)</option>
                        <option value="N2O" {% if coefficient.gas == 'N2O' %}selected{% endif %}>氧化亚氮 (N2O)</option>
                        <option value="HFCs" {% if coefficient.gas == 'HFCs' %}selected{% endif %}>氢氟碳化物 (HFCs)</option>
                        <option value="PFCs" {% if coefficient.gas == 'PFCs' %}selected{% endif %}>全氟碳化物 (PFCs)</option>
                        <option value="SF6" {% if coefficient.gas == 'SF6' %}selected{% endif %}>六氟化硫 (SF6)</option>
                        <option value="NF3" {% if coefficient.gas == 'NF3' %}selected{% endif %}>三氟化氮 (NF3)</option>
                    </select>
                </div>
                
                <div class="mb-3">
                    <label for="source" class="form-label">数据来源</label>
                    <input type="text" class="form-control" id="source" name="source" value="{{ coefficient.source }}" required>
                </div>
                
                <div class="mb-3">
                    <label for="category_id" class="form-label">所属分类</label>
                    <select class="form-select" id="category_id" name="category_id" required>
                        {% for category in categories %}
                            <option value="{{ category.id }}" {% if coefficient.category_id == category.id %}selected{% endif %}>
                                {{ '　' * (category.level - 1) }}|-- {{ category.name }}
                            </option>
                        {% endfor %}
                    </select>
                </div>
                
                <div class="d-flex justify-content-between">
                    <a href="{{ url_for('coefficient.coefficient_list') }}" class="btn btn-secondary">取消</a>
                    <button type="submit" class="btn btn-primary">保存修改</button>
                </div>
            </form>
        </div>
    </div>
</div>
{% endblock %}